/*
	求和运算
*/

#include <stdio.h>

struct res{
		int n;
		int sum;
	};
struct res arr[1024];

int main (){
	int i = 0;
	int sum = 0;
	int n = 10;
	//算法一：
	while(1){
		printf("请输入一个值：\n");
		scanf("%d",&n);
		for(i = 0;i < n;i++){
			sum += i;//时间复杂度O(n)
		}	
		printf("sum = %d\n",sum);
	}

#if 0
	//算法二：
	sum = (1 + n) * n / 2;//时间复杂度O(1)
	printf("sum = %d\n",sum);
#endif
}
